﻿#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.dll"
#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.Runtime.dll"

#load "Client.fs"

open Client
open Microsoft.SharePoint.Client
open Microsoft.SharePoint.Client.Application
open System.Security;

// ========================================================================
// Modifying the Document ID field and customizing the Document ID settings
// ========================================================================

let web = Client.Context.Web

let spList = web.Lists.GetByTitle("Documents")

Client.Load spList

let query= CamlQuery.CreateAllItemsQuery()
let listItems = spList.GetItems(query)

Client.Load listItems

let item = listItems.GetById(19)
Client.Load item
item.FieldValues

let fld = spList.Fields.GetByInternalNameOrTitle("_dlc_DocIdUrl")
Client.Load fld
fld.Hidden <- false
fld.SetShowInDisplayForm(true)
fld.SetShowInEditForm(true)
fld.SetShowInNewForm(true)
fld.Update()
Client.ExecuteQuery()

web.AllProperties.["docid_msft_hier_siteprefix"] <- "88888"
web.AllProperties.["docid_settings_ui"] <- "<?xml version=\"1.0\" encoding=\"utf-16\"?><DocIdUiSettings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Prefix>88888</Prefix><AssignmentEnabled>true</AssignmentEnabled></DocIdUiSettings>"; 
web.Update()
Client.ExecuteQuery()